package com.ruibang.glass.quality.component.job;

import com.ruibang.glass.quality.constant.Constants;
import com.ruibang.glass.quality.domain.req.DefectLossReq;
import com.ruibang.glass.quality.service.TotalEquDataService;
import com.teaming.cloud.framework2.elastic.job3.annotation.ElasticJobScheduler;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-01-30  09:15
 * @Description: TODO:致命缺陷损失数据(每天)
 * @Version: 1.0
 */

@Slf4j
@ElasticJobScheduler(cron = "1 20 7 * * ?", name = "EverydayFatalDefectTask", shardingItemParameters = "0=0", jobParameters = "parameter")
//@ElasticJobScheduler(cron = "1 * * * * ?", name = "EverydayFatalDefectTask")
@Component
public class EverydayFatalDefectTask implements SimpleJob {

    @Autowired
    private TotalEquDataService totalEquDataService;


    @Override
    public void execute(ShardingContext shardingContext) {
        LocalDate now = LocalDate.now();
        String startDate = now.minusDays(Constants.DEFECT_DEFAULT_QUERY_DAYS).format(DateTimeFormatter.ISO_LOCAL_DATE);
        String endDate = now.format(DateTimeFormatter.ISO_LOCAL_DATE);
        DefectLossReq defectLossReq = new DefectLossReq();
        defectLossReq.setStartDate(startDate);
        defectLossReq.setEndDate(endDate);
        totalEquDataService.importEverydayDefectLoss(defectLossReq);
    }


}
